<?php

namespace App\Http\Controllers;


use Gregwar\Captcha\CaptchaBuilder;
use Gregwar\Captcha\PhraseBuilder;

class CustomController extends Controller
{
  /**
   * 获取验证码
   */
  public function getCode()
  {
    $phraseBuilder = new PhraseBuilder(4);
    //生成验证码图片的Builder对象，配置相应属性
    $builder = new CaptchaBuilder(null, $phraseBuilder);
    //可以设置图片宽高及字体
    $builder->build($width = 100, $height = 50, $font = null);
    //获取验证码的内容
    $phrase = $builder->getPhrase();
    //把内容存入session
    \Illuminate\Support\Facades\Session::flash('codes', $phrase);
    //生成图片
    header("Cache-Control: no-cache, must-revalidate");
    header('Content-Type: image/jpeg');
    $builder->output();
  }
}